package org.example.library.controller;

import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;

import org.aspectj.lang.annotation.AdviceName;
import org.example.library.constant.Constants;
import org.example.library.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.scanner.Constant;

@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/login")
    public Boolean login(String name, String password, HttpSession  session){
        if (!StringUtils.hasLength(name)||!StringUtils.hasLength(password)){
            return false;
        }
//        if ("qqqq".equals(name)&&"qqqq".equals(password)){
//            return true;
//        }
        Boolean isLogin=userService.checkPassword(name,password);
        if (isLogin){
            session.setAttribute(Constants.SESSION_USER_NAME,name);
        }
        return userService.checkPassword(name, password);
    }
}
